import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: 'Holyzq 管理系统', icon: 'dashboard' }
      }
    ]
  },

  {
    path: '/shopCenter',
    component: Layout,
    name: 'ShopCenter',
    meta: { title: '商城中心', icon: 'el-icon-shopping-cart-2' },
    children: [
      {
        path: '/tag',
        name: 'Tag',
        component: () => import('@/views/tag/index'),
        meta: { title: '标签管理', icon: 'el-icon-star-off' }
      },
      {
        path: '/notice',
        name: 'Notice',
        component: () => import('@/views/notice/index'),
        meta: { title: '通知管理', icon: 'el-icon-bell' }
      },
      {
        path: '/notice/create',
        name: 'NoticeCreate',
        component: () => import('@/views/notice/create'),
        meta: { title: '新增通知', icon: 'el-icon-bell', activeMenu: '/shopCenter/notice' },
        hidden: true
      },
      {
        path: '/notice/edit/:id',
        name: 'NoticeEdit',
        component: () => import('@/views/notice/edit'),
        meta: { title: '编辑通知', icon: 'el-icon-bell', activeMenu: '/shopCenter/notice' },
        hidden: true
      },
      {
        path: '/category',
        name: 'Category',
        component: () => import('@/views/category/index'),
        meta: { title: '栏目管理', icon: 'el-icon-date' }
      },
      {
        path: '/category/create',
        name: 'CategoryCreate',
        component: () => import('@/views/category/create'),
        meta: { title: '新增栏目', icon: 'el-icon-date', activeMenu: '/shopCenter/category' },
        hidden: true
      },
      {
        path: '/category/edit/:id',
        name: 'CategoryEdit',
        component: () => import('@/views/category/edit'),
        meta: { title: '编辑栏目', icon: 'el-icon-date', activeMenu: '/shopCenter/category' },
        hidden: true
      },
      {
        path: '/product',
        name: 'Product',
        component: () => import('@/views/product/index'),
        meta: { title: '商品管理', icon: 'el-icon-goods' }
      },
      {
        path: '/product/create',
        name: 'ProductCreate',
        component: () => import('@/views/product/create'),
        meta: { title: '新增商品', icon: 'el-icon-goods', activeMenu: '/shopCenter/product' },
        hidden: true
      },
      {
        path: '/product/edit/:id',
        name: 'ProductEdit',
        component: () => import('@/views/product/edit'),
        meta: { title: '编辑商品', icon: 'el-icon-goods', activeMenu: '/shopCenter/product' },
        hidden: true
      },
      {
        path: '/express',
        name: 'Express',
        component: () => import('@/views/express/index'),
        meta: { title: '物流管理', icon: 'el-icon-truck' }
      },
      {
        path: '/express/create',
        name: 'ExpressCreate',
        component: () => import('@/views/express/create'),
        meta: { title: '新增物流', icon: 'el-icon-truck', activeMenu: '/shopCenter/express' },
        hidden: true
      },
      {
        path: '/express/edit/:id',
        name: 'ExpressEdit',
        component: () => import('@/views/express/edit'),
        meta: { title: '编辑物流', icon: 'el-icon-truck', activeMenu: '/shopCenter/express' },
        hidden: true
      },
      {
        path: '/advert',
        name: 'Advert',
        component: () => import('@/views/advert/index'),
        meta: { title: '广告管理', icon: 'el-icon-postcard' }
      },
      {
        path: '/advert/create',
        name: 'AdvertCreate',
        component: () => import('@/views/advert/create'),
        meta: { title: '新增广告', icon: 'el-icon-postcard', activeMenu: '/shopCenter/advert' },
        hidden: true
      },
      {
        path: '/advert/edit/:id',
        name: 'AdvertEdit',
        component: () => import('@/views/advert/edit'),
        meta: { title: '编辑广告', icon: 'el-icon-postcard', activeMenu: '/shopCenter/advert' },
        hidden: true
      },
      {
        path: '/order',
        name: 'Order',
        component: () => import('@/views/order/index'),
        meta: { title: '订单管理', icon: 'el-icon-s-order' }
      },
      {
        path: '/order/show/:id',
        name: 'OrderShow',
        component: () => import('@/views/order/show'),
        meta: { title: '订单详情', icon: 'el-icon-s-order', activeMenu: '/shopCenter/order' },
        hidden: true
      },
      {
        path: '/brand',
        name: 'Brand',
        component: () => import('@/views/brand/index'),
        meta: { title: '品牌管理', icon: 'el-icon-apple' }
      },
      {
        path: '/brand/create',
        name: 'BrandCreate',
        component: () => import('@/views/brand/create'),
        meta: { title: '新增品牌', icon: 'el-icon-apple', activeMenu: '/shopCenter/brand' },
        hidden: true
      },
      {
        path: '/brand/edit/:id',
        name: 'BrandEdit',
        component: () => import('@/views/brand/edit'),
        meta: { title: '编辑品牌', icon: 'el-icon-apple', activeMenu: '/shopCenter/brand' },
        hidden: true
      },
      {
        path: '/article',
        name: 'Article',
        component: () => import('@/views/article/index'),
        meta: { title: '文章管理', icon: 'el-icon-document' }
      },
      {
        path: '/article/create',
        name: 'ArticleCreate',
        component: () => import('@/views/article/create'),
        meta: { title: '新增文章', icon: 'el-icon-document', activeMenu: '/shopCenter/article' },
        hidden: true
      },
      {
        path: '/article/edit/:id',
        name: 'ArticleEdit',
        component: () => import('@/views/article/edit'),
        meta: { title: '编辑文章', icon: 'el-icon-apple', activeMenu: '/shopCenter/article' },
        hidden: true
      },
      {
        path: '/charts',
        name: 'Charts',
        component: () => import('@/views/charts/index'),
        meta: { title: '数据统计', icon: 'shujutongji' }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    name: 'System',
    meta: { title: '系统中心', icon: 'el-icon-setting' },
    children: [
      {
        path: '/user',
        name: 'User',
        component: () => import('@/views/user/index'),
        meta: { title: '用户管理', icon: 'el-icon-user' }
      },
      {
        path: '/user/create',
        name: 'UserCreate',
        component: () => import('@/views/user/create'),
        meta: { title: '新增用户', icon: 'el-icon-user', activeMenu: '/system/user' },
        hidden: true
      },
      {
        path: '/user/edit/:id',
        name: 'UserEdit',
        component: () => import('@/views/user/edit'),
        meta: { title: '编辑用户', icon: 'el-icon-user', activeMenu: '/system/user' },
        hidden: true
      },
      {
        path: '/role',
        name: 'Role',
        component: () => import('@/views/role/index'),
        meta: { title: '用户组管理', icon: 'el-icon-user-solid' }
      },
      {
        path: '/role/create',
        name: 'RoleCreate',
        component: () => import('@/views/role/create'),
        meta: { title: '新增用户组', icon: 'el-icon-user-solid', activeMenu: '/system/role' },
        hidden: true
      },
      {
        path: '/role/edit/:id',
        name: 'RoleEdit',
        component: () => import('@/views/role/edit'),
        meta: { title: '编辑用户组', icon: 'el-icon-user-solid', activeMenu: '/system/role' },
        hidden: true
      },
      {
        path: '/permission',
        name: 'Permission',
        component: () => import('@/views/permission/index'),
        meta: { title: '菜单与权限', icon: 'el-icon-s-claim' }
      },
      {
        path: '/permission/create',
        name: 'PermissionCreate',
        component: () => import('@/views/permission/create'),
        meta: { title: '新增权限', icon: 'el-icon-s-claim', activeMenu: '/system/permission' },
        hidden: true
      },
      {
        path: '/permission/edit/:id',
        name: 'PermissionEdit',
        component: () => import('@/views/permission/edit'),
        meta: { title: '编辑权限', icon: 'el-icon-s-claim', activeMenu: '/system/permission' },
        hidden: true
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
